home *** CD-ROM | disk | FTP | other *** search
/ Mac Mania 4 / MacMania 4.toast / / Tools&Utilities / duo-depth-10b1-strip / Source / DuoDepth.p next >
Text File  |  1995-07-07  |  7KB  |  236 lines

  1. unit DuoDepth;
  2. (*
  3. # Copyright Quinn "The Eskimo!"
  4. # Created : Quinn
  5. # Station : Eriodon
  6. # Date : Friday, 7 July 1995
  7. *)
  8. interface
  9.  
  10.     uses
  11.         Types,
  12.         ControlStrip,
  13.         GestaltEqu,
  14.         Resources,
  15.         Displays,
  16.         Icons,
  17.         ToolUtils;
  18.     
  19.     type
  20.         myGlobals =
  21.             record
  22.                 popup_menu : MenuHandle;
  23.                 main_icon : Handle;
  24.                 arrow_picture : PicHandle;
  25.                 help_string : Str255;
  26.             end;
  27.         myGlobalsPtr = ^myGlobals;
  28.         myGlobalsHandle = ^myGlobalsPtr;
  29.         
  30.     function Main(message : longint;
  31.                               globals : myGlobalsHandle;
  32.                               statusRect : RectPtr;
  33.                               statusPort : GrafPtr) : longint;
  34.  
  35. implementation
  36.  
  37.         
  38.     const
  39.          kMyModuleWidth = 26;
  40.          kBaseDisplayMode = 128;            (* base sRsrc *)
  41.          (* Normally you'd find this out by walking the Slot Manager data structures
  42.                   but I'm too lazy so I'm hardwiring this for the Duo 280c.  This is why
  43.                  this module does a check for specific hardware. Also it assumes you're
  44.                  not docked and using some other video device as the main device. Altogether
  45.                  very skanky but it works for *my* Duo, and that's what counts.
  46.          *)
  47.          
  48.          (* MENU *)
  49.          rPopupMenu = 256;
  50.          
  51.          iThousandsColours = 1;
  52.          i256Colours = 2;
  53.          
  54.          (* STR  *)
  55.          rHelpString = 256;
  56.          
  57.          (* ics# *)
  58.          rMainIcon = 256;
  59.          
  60.          (* PICT *)
  61.          rArrowPicture = 256;
  62.          
  63.     function Main(message : longint;
  64.                               globals : myGlobalsHandle;
  65.                               statusRect : RectPtr;
  66.                               statusPort : GrafPtr) : longint;
  67.  
  68.         procedure CleanGlobals(tmp_globals : myGlobalsHandle);
  69.             var
  70.                 junk : OSErr;
  71.         begin
  72.             if tmp_globals^^.popup_menu <> nil then begin
  73.                 DisposeHandle(Handle(tmp_globals^^.popup_menu));
  74.                 tmp_globals^^.popup_menu := nil;
  75.             end; (* if *)
  76.             if tmp_globals^^.arrow_picture = nil then begin
  77.                 KillPicture(tmp_globals^^.arrow_picture);
  78.                 tmp_globals^^.arrow_picture:= nil;
  79.             end; (* if *)
  80.             if tmp_globals^^.main_icon = nil then begin
  81.                 junk := DisposeIconSuite(tmp_globals^^.main_icon, true);
  82.                 tmp_globals^^.main_icon:= nil;
  83.             end; (* if *)
  84.         end; (* CleanGlobals *)
  85.         
  86.         function InitModule : longint;
  87.             var
  88.                 err : OSErr;
  89.                 new_globals : myGlobalsHandle;
  90.                 response : longint;
  91.         begin
  92.             new_globals := nil;
  93.             err := Gestalt(gestaltMachineType, response);
  94.             if (err = noErr) & (response <> gestaltPowerBookDuo280c) then begin
  95.                 err := -1;
  96.             end; (* if *)
  97.             (* create and init my globals *)
  98.             if err = noErr then begin
  99.                 new_globals := myGlobalsHandle(NewHandle(sizeof(myGlobals)));
  100.                 err := MemError;
  101.             end; (* if *)
  102.             if err = noErr then begin
  103.                 HLock(Handle(new_globals));
  104.                 new_globals^^.popup_menu := nil;
  105.                 new_globals^^.help_string := GetString(rHelpString)^^;
  106.                 new_globals^^.popup_menu := GetMenu(rPopupMenu);
  107.                 if new_globals^^.popup_menu = nil then begin
  108.                     err := resNotFound;
  109.                 end else begin
  110.                     DetachResource(Handle(new_globals^^.popup_menu));
  111.                 end; (* if *)
  112.             end; (* if *)
  113.             if err = noErr then begin
  114.                 err := SBGetDetachIconSuite(new_globals^^.main_icon, rMainIcon, svAllSmallData);
  115.             end; (* if *)
  116.             if err = noErr then begin
  117.                 new_globals^^.arrow_picture := GetPicture(rArrowPicture);
  118.                 if new_globals^^.arrow_picture = nil then begin
  119.                     err := resNotFound;
  120.                 end else begin
  121.                     DetachResource(Handle(new_globals^^.arrow_picture));
  122.                 end; (* if *)
  123.             end; (* if *)
  124.             (* setup the result *)            
  125.             if err = noErr then begin
  126.                 HUnlock(Handle(new_globals));
  127.                 InitModule := longint(new_globals);
  128.             end else begin
  129.                 CleanGlobals(new_globals);
  130.                 if new_globals <> nil then begin
  131.                     DisposeHandle(Handle(new_globals));
  132.                 end; (* if *)
  133.                 InitModule := longint(err);
  134.             end; (* if *)
  135.         end; (* InitModule *)
  136.         
  137.         function CloseModule : longint;
  138.         begin
  139.             (* clean my globals *)
  140.             CleanGlobals(globals);
  141.             (* dispose my globals *)
  142.             DisposeHandle(Handle(globals));
  143.             CloseModule := 0;        (* ControlStrip doesn't care what we return *)
  144.         end; (* CloseModule *)
  145.         
  146.         function DrawStatus : longint;
  147.             var
  148.                 plot_rect : Rect;
  149.                 junk : OSErr;
  150.         begin
  151.             (* draw the main icon *)
  152.             plot_rect.topLeft := statusRect^.topLeft;
  153.             plot_rect.right := plot_rect.left + 16;
  154.             plot_rect.bottom := plot_rect.top + 16;
  155.             junk := PlotIconSuite(plot_rect, atNone, ttNone, globals^^.main_icon);
  156.             (* draw the arrow *)
  157.             plot_rect := globals^^.arrow_picture^^.picFrame;
  158.             OffsetRect(plot_rect, -plot_rect.left, -plot_rect.top);
  159.             OffsetRect(plot_rect, statusRect^.left + 16, statusRect^.top);
  160.             OffsetRect(plot_rect, 0, (statusRect^.bottom - plot_rect.bottom) div 2); (* sneaky way to centre vertically *)
  161.             DrawPicture(globals^^.arrow_picture, plot_rect);
  162.             DrawStatus := 0;        (* ControlStrip doesn't care what we return *)
  163.         end; (* DrawStatus *)
  164.         
  165.         function MouseClick : longint;
  166.             var
  167.                 err : OSErr;
  168.                 menu_item : integer;
  169.                 video_depth_long : longint;
  170.                 main_device : GDHandle;
  171.                 currently_small : boolean;
  172.         begin
  173.             main_device := GetMainDevice;
  174.             (* Yucky assumption here!  If the screen height is less than 480 pixels *)
  175.             (*  then we're in 640 x 400, else we're in 640 x 480. *)
  176.             currently_small := (main_device^^.gdRect.bottom - main_device^^.gdRect.top) < 480;
  177.             if currently_small then begin
  178.                 SetItemMark(globals^^.popup_menu, iThousandsColours, '•');
  179.                 SetItemMark(globals^^.popup_menu, i256Colours, ' ');
  180.             end else begin
  181.                 SetItemMark(globals^^.popup_menu, iThousandsColours, ' ');
  182.                 SetItemMark(globals^^.popup_menu, i256Colours, '•');
  183.             end; (* if *)
  184.             menu_item := SBTrackpopupMenu(statusRect^, globals^^.popup_menu);
  185.             if menu_item <> 0 then begin
  186.                 video_depth_long := 32;        (* request maximum bit depth for the mode *)
  187.                 err := DMSetDisplayMode(main_device,
  188.                                         menu_item - 1 + kBaseDisplayMode,
  189.                                         video_depth_long,
  190.                                         0,
  191.                                         nil);
  192.                 if err <> noErr then begin
  193.                     DebugStr('Error setting mode.');
  194.                 end; (* if *)
  195.             end; (* if *)
  196.             MouseClick := 0;    (* same bits as sdevPeriodicTickle *)
  197.         end; (* MouseClick *)
  198.         
  199.         function ShowBalloonHelp : longint;
  200.             var
  201.                 tmpstr : Str255;
  202.         begin
  203.             tmpstr := globals^^.help_string;
  204.             ShowBalloonHelp := SBShowHelpString(statusRect^, @tmpstr);
  205.         end; (* ShowBalloonHelp *)
  206.         
  207.         var
  208.             result : longint;
  209.     begin
  210.         case message of
  211.             sdevInitModule:
  212.                 result := InitModule;
  213.             sdevCloseModule:
  214.                 result := CloseModule;
  215.             sdevFeatures:
  216.                 result := bsl(1, sdevWantMouseClicks)
  217.                                         + bsl(1, sdevDontAutoTrack)
  218.                                         + bsl(1, sdevHasCustomHelp);
  219.             sdevGetDisplayWidth:
  220.                 result := kMyModuleWidth;
  221.             sdevPeriodicTickle:
  222.                 result := 0;
  223.             sdevDrawStatus:
  224.                 result := DrawStatus;
  225.             sdevMouseClick:
  226.                 result := MouseClick;
  227.             sdevShowBalloonHelp:
  228.                 result := ShowBalloonHelp;
  229.         otherwise
  230.             result := 0;
  231.         end; (* case *)
  232.         Main := result;
  233.     end; (* Main *)
  234.  
  235. end. (* DuoDepth *)
  236.